/*
 * @Author: 贺楠 1071780426@qq.com
 * @Date: 2024-08-14 16:36:28
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-08-19 13:55:09
 * @FilePath: \newMould_BHZ\src\components\rawMaterialManage\rawTestFrequency\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import TableData from "@/components/public/el-table"; //主页面列表

import {
    saveDetectionFrequency, //保存
    setDetectionFrequency,//设置
    searchDetectionFrequency, //详情

} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "statusNum",
        "currentRow",
        "showName",
        "commonData"

    ],
    data() {
        return {
            visible: "",
            loading: false,
            title: null,
            isLock: false,
            dialogHeight: null,
            treeData: [], //材料种类
            formData: {

            },
            formObj: null,
            formDatafileList: [], //工作计划资料
            btnShow: true,
            currentDetail: null,
            selected: [],
            getList:null,
            table_config: formJs.table_config, //列表
            tableData: [],  
            width:null ,
            top:null
            // typs: null
        };
    },
    components: {
        publicForm,
        TableData
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        commonData: {
            handler(newVal) {
                if (newVal) {
                    this.getList = newVal;
                }
            },
            immediate: true,
        },

        statusNum: {
            handler(newVal) {
                if (newVal) {

                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    if (this.statusNum == 7) {
                        this.getDetail({
                            fId: this.currentDetail.fId
                        })
                    }
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：
    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
        this.btnShow = true

        if (this.statusNum == 1) { //新增
            this.formData = {
                companyId: this.getList.fCompanyid,
                companyName: this.showName,
                startDates: this.common.day(0),
                endDates: this.common.day(0)
            }
            this.formObj = formJs.formObj;
            this.btnShow = true;
            this.title="统计周期";
            this.width="500px";
            this.top="15%";

        } else if (this.statusNum == 10) { //设置
            this.formData = {
                companyId: this.getList.fCompanyid,
                companyName: this.showName,
                plLastMonth: 1,
                plThisMonth: this.common.daye(0)
            }
            this.formObj = formJs.formSetObj;
            this.btnShow = true;
            this.title="统计周期";
            this.width="500px";
            this.top="15%";


        } else if (this.statusNum == 7) { //查看
            this.btnShow = false;
            this.title="查看";
            this.width="1060px";
            this.top="5%";

          
        }
        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            if (this.statusNum == 7) { //新增
                this.dialogHeight = h * 0.76 + "px";
            }else {
                this.dialogHeight = h * 0.3 + "px";

            }
            
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
   
        edit() {
            this.formData = this.$options.data.call(this).formData;
        },

        // 详情
        getDetail(obj) {
            this.loading = true;
            searchDetectionFrequency(obj).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;
                    var data = res.data
                    this.tableData = data;
                } else {
                    this.loading = false;
                    this.$message.error(res.msg);
                }
            });
        },
        yj_saveForm(status) {
            // 0连续新增1新增
            if (this.$refs.publicForm.submitForm()) {
                this.saveForm(this.formData, status);
            } else {
                console.log("error");
            }
        },
        // 保存
        saveForm(data, status) {
            this.loading = true;
            this.isLock = true;
            var str;
            if(this.statusNum==1){
                str=saveDetectionFrequency;//新增
            }else if(this.statusNum==10){
                str=setDetectionFrequency;//设置
            }
            str(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = false;
                        this.visible = false;
                        this.$emit("refreshList", status);
                        this.$message.success("新增成功");
                        this.isLock = false
                    }  else {
                        this.loading = false;
                        this.isLock = false
                        this.$message.error(res.data);
                    }
                })
        },
    },
};